
--
-- Select Database: 'F12I4DAB1H2Gr2'
--
USE F12I4DAB1H2Gr2
GO
 
IF DB_NAME() = 'F12I4DAB1H2Gr2'
    RAISERROR('''F12I4DAB1H2Gr2'' DATABASE CONTEXT NOW IN USE.',1,1)
ELSE
    RAISERROR('ERROR IN BATCH FILE, ''USE F12I4DAB1H2Gr2'' FAILED!  KILLING THE SPID NOW.',22,127) WITH LOG
 
GO
EXECUTE SP_DBOPTION 'F12I4DAB1H2Gr2' ,'TRUNC. LOG ON CHKPT.' ,'TRUE'
GO

--
-- Create Table    : 'ControlCenter'   
-- ID              :  
-- Name            :  
-- Address         :  
-- Country         :  
-- ContactInfo     :  
-- ContactNumber   :  
--
CREATE TABLE ControlCenter (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Name           VARCHAR(255) NOT NULL,
    Address        VARCHAR(255) NOT NULL,
    Country        VARCHAR(255) NOT NULL,
    ContactInfo    VARCHAR(255) NOT NULL,
    ContactNumber  VARCHAR(255) NOT NULL,
CONSTRAINT pk_ControlCenter PRIMARY KEY CLUSTERED (ID))
GO

--
-- Create Table    : 'Node'   
-- ID              :  
-- Address         :  
-- Country         :  
-- Description     :  
-- ControlCenter   :  (references ControlCenter.ID)
--
CREATE TABLE Node (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Address        VARCHAR(255) NOT NULL,
    Country        VARCHAR(255) NOT NULL UNIQUE,
    Description    VARCHAR(255) NOT NULL,
    ControlCenter  INT NULL,
CONSTRAINT pk_Node PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_Node FOREIGN KEY (ControlCenter)
    REFERENCES ControlCenter (ID)
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'Pool'   
-- ID              :  
-- Fluctuation     :  
-- Node            :  (references Node.ID)
--
CREATE TABLE Pool (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Fluctuation    REAL NOT NULL,
    Node           INT NOT NULL,
CONSTRAINT pk_Pool PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_Pool FOREIGN KEY (Node)
    REFERENCES Node (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'Park'   
-- ID              :  
-- Location        :  
-- OnLand          :  
-- Pool            :  (references Pool.ID)
--
CREATE TABLE Park (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Location       VARCHAR(255) NOT NULL,
    OnLand         BIT NOT NULL,
    Pool           INT NOT NULL,
CONSTRAINT pk_Park PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_Park FOREIGN KEY (Pool)
    REFERENCES Pool (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'Windmill'   
-- ID              :  
-- Park            :  (references Park.ID)
-- Name            :  
-- Location        :  
--
CREATE TABLE Windmill (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Park           INT NOT NULL,
    Name           VARCHAR(255) NOT NULL,
    Location       VARCHAR(255) NOT NULL,
CONSTRAINT pk_Windmill PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_Windmill FOREIGN KEY (Park)
    REFERENCES Park (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'ADE'   
-- ID              :  
-- Park            :  (references Park.ID)
-- Description     :  
-- Manufacturer    :  
-- PartNr          :  
-- ContactInfo     :  
-- ContactNumber   :  
--
CREATE TABLE ADE (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Park           INT NOT NULL,
    Description    VARCHAR(255) NOT NULL,
    Manufacturer   VARCHAR(255) NOT NULL,
    PartNr         VARCHAR(255) NOT NULL,
    ContactInfo    VARCHAR(255) NOT NULL,
    ContactNumber  VARCHAR(255) NOT NULL,
CONSTRAINT pk_ADE PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_ADE FOREIGN KEY (Park)
    REFERENCES Park (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'Windmill_Measures'   
-- ID              :  
-- Description     :  
-- Data            :  
-- Windmill        :  (references Windmill.ID)
--
CREATE TABLE Windmill_Measures (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Description    VARCHAR(255) NOT NULL,
    Data           REAL NOT NULL,
    Windmill       INT NOT NULL,
CONSTRAINT pk_Windmill_Measures PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_Windmill_Measures FOREIGN KEY (Windmill)
    REFERENCES Windmill (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'Windmill_Components'   
-- ID              :  
-- Description     :  
-- Manufacturer    :  
-- Windmill        :  (references Windmill.ID)
-- PartNr          :  
-- ContactInfo     :  
-- ContactNumber   :  
--
CREATE TABLE Windmill_Components (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Description    VARCHAR(255) NOT NULL,
    Manufacturer   VARCHAR(255) NOT NULL,
    Windmill       INT NOT NULL,
    PartNr         VARCHAR(255) NOT NULL,
    ContactInfo    VARCHAR(255) NOT NULL,
    ContactNumber  VARCHAR(255) NOT NULL,
CONSTRAINT pk_Windmill_Components PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_Windmill_Components FOREIGN KEY (Windmill)
    REFERENCES Windmill (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'Windmill_Constructions'   
-- ID              :  
-- Windmill        :  (references Windmill.ID)
-- Description     :  
-- Manufacturer    :  
-- PartNr          :  
-- ContactInfo     :  
-- ContactNumber   :  
--
CREATE TABLE Windmill_Constructions (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Windmill       INT NOT NULL,
    Description    VARCHAR(255) NOT NULL,
    Manufacturer   VARCHAR(255) NOT NULL,
    PartNr         VARCHAR(255) NOT NULL,
    ContactInfo    VARCHAR(255) NOT NULL,
    ContactNumber  VARCHAR(255) NOT NULL,
CONSTRAINT pk_Windmill_Constructions PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_Windmill_Constructions FOREIGN KEY (Windmill)
    REFERENCES Windmill (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'ADE_Measures'   
-- ID              :  
-- ADE             :  (references ADE.ID)
-- Description     :  
-- Data            :  
--
CREATE TABLE ADE_Measures (
    ID             INT IDENTITY NOT NULL UNIQUE,
    ADE            INT NOT NULL,
    Description    VARCHAR(255) NOT NULL,
    Data           REAL NOT NULL,
CONSTRAINT pk_ADE_Measures PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_ADE_Measures FOREIGN KEY (ADE)
    REFERENCES ADE (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO

--
-- Create Table    : 'ControlCenter_Permissions'   
-- ID              :  
-- Name            :  
-- Description     :  
-- Data            :  
-- ControlCenter   :  (references ControlCenter.ID)
--
CREATE TABLE ControlCenter_Permissions (
    ID             INT IDENTITY NOT NULL UNIQUE,
    Description    VARCHAR(255) NOT NULL,
    Data           BIT NOT NULL,
    ControlCenter  INT NOT NULL,
CONSTRAINT pk_ControlCenter_Permissions PRIMARY KEY CLUSTERED (ID),
CONSTRAINT fk_ControlCenter_Permissions FOREIGN KEY (ControlCenter)
    REFERENCES ControlCenter (ID)
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
GO



--
-- Permissions for: 'public'
--
GRANT ALL ON ControlCenter TO public
GO
GRANT ALL ON Node TO public
GO
GRANT ALL ON Pool TO public
GO
GRANT ALL ON Park TO public
GO
GRANT ALL ON Windmill TO public
GO
GRANT ALL ON ADE TO public
GO
GRANT ALL ON Windmill_Measures TO public
GO
GRANT ALL ON Windmill_Components TO public
GO
GRANT ALL ON Windmill_Constructions TO public
GO
GRANT ALL ON ADE_Measures TO public
GO
GRANT ALL ON ControlCenter_Permissions TO public
GO

